<!--
 * @Author: your name
 * @Date: 2020-02-21 16:51:07
 * @LastEditTime: 2020-02-23 00:22:34
 * @LastEditors: Please set LastEditors
 * @Description: 登录
 * @FilePath: /dongyang/src/views/Login.vue
 -->
<template>
  <div class="page-login" id="container">
    <van-cell-group>
      <van-field
        v-model="mobile"
        required
        clearable
        label="手机号"
        maxlength="11"
        placeholder="请输入手机号"
      />
      <van-field
        v-model="password"
        type="password"
        required
        center
        clearable
        label="密码"
        placeholder="请输入密码"
      />
    </van-cell-group>

    <van-button type="primary" size="large" @click.native="login">登录</van-button>
    <div class="register" @click="$router.push('/register')">没有账号，去注册？</div>
  </div>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { login } from "@/apis/index.ts";
import { setToken,setTimeDate } from "@/utils";
@Component
export default class Login extends Vue {
  private mobile: any = "";
  private password: any = "";
  public async login() {
    if (!this.mobile || !this.password) {
      this.$toast("手机号或密码不能为空");
      return false;
    }
    const params = {
      mobile: this.mobile,
      password: this.password
    };
    const data = await login(params);
    setToken(data.token);
    setTimeDate(data.timeout)
    this.$router.push("/home");
  }
}
</script>
<style lang="scss">
.page-login {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  .van-cell-group {
    padding-top: 120px;
  }
  .van-cell__value {
    padding-left: 12px;
  }
  > button {
    box-sizing: border-box;
    border-radius: 48px;
    width: 80%;
    margin: 0 auto;
    margin-top: 64px;
    display: block;
  }
  .van-button--primary {
    background-color: #1989fa;
    border: 1px solid #1989fa
  }
  .register {
    text-align: left;
    margin-top: 50px;
    margin-left: 30px;
  }
}
</style>
